// $Id: Collection.cs 10 2008-02-29 15:58:02Z mcartoixa $
/*
 *  Copyright (C) 2007 Noury Solutions
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
/*! \file
 * \brief Definition of Domain Model collections.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace Salamanca.DataAccess.Collections
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Implements a read-only <include file="../doc/Global.doc.xml" path="doc/template[@name='DomainModel']/*" /> collection.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public class ReadOnlyDomainModelCollection<TDomainModel>:
        ReadOnlyCollection<TDomainModel>
        where TDomainModel:
            IDomainModel
    {

        /// <summary>Initializes a new instance of the <see cref="ReadOnlyDomainModelCollection{TDomainModel}" /> class that is a read-only wrapper around the specified list.</summary>
        /// <param name="list">The list to wrap.</param>
        public ReadOnlyDomainModelCollection(IList<TDomainModel> list):
            base(list)
        {
        }

    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Implements a  <include file="../doc/Global.doc.xml" path="doc/template[@name='DomainModel']/*" /> collection.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public class DomainModelCollection<TDomainModel>:
        Collection<TDomainModel>
        where TDomainModel:
            IDomainModel
    {

        /// <summary>Initializes a new instance of the <see cref="DomainModelCollection{TDomainModel}" /> class.</summary>
        public DomainModelCollection():
            base()
        {
        }

        /// <summary>Initializes a new instance of the <see cref="DomainModelCollection{TDomainModel}" /> class as a wrapper around the specified list.</summary>
        /// <param name="list">The list to wrap.</param>
        public DomainModelCollection(IList<TDomainModel> list):
            base(list)
        {
        }

    }



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Implements a <include file="../doc/Global.doc.xml" path="doc/template[@name='DataMapper']/*" /> collection.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

    public class DataMapperCollection:
        Dictionary<Type, IDataMapper>
    {

        /// <summary>Initializes a new instance of the <see cref="DataMapperCollection" /> class.</summary>
        public DataMapperCollection():
            this(new PersistenceContextProvider())
        {
        }

        /// <summary>Initializes a new instance of the <see cref="DataMapperCollection" /> class.</summary>
        public DataMapperCollection(IPersistenceContextProvider provider):
            base()
        {
            _Provider=provider;
        }

        internal IPersistenceContext CreatePersistenceContext()
        {
            return _Provider.CreatePersistenceContext();
        }

        internal IPersistenceContext CreatePersistenceContext(bool forceAction)
        {
            return _Provider.CreatePersistenceContext(forceAction);
        }

        /// <summary>Gets or sets the <see cref="PersistenceContextProvider" /> instance.</summary>
        public IPersistenceContextProvider PersistenceContextProvider
        {
            get
            {
                return _Provider;
            }
            set
            {
                _Provider=value;
            }
        }

        private IPersistenceContextProvider _Provider;
    }
}
